﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Classes;
namespace FlightSystemDBLayer
{
    public class DBCity : ICity
    {

        SQLAccess c;

        public DBCity() // suspicious ? maybe not needed
        {
            c = new SQLAccess();
        }

        public IList<City> GetDBCities()
        {
            City a;
            DataSet ds = new DataSet();
            IList<City> list = new List<City>();
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = new SqlCommand(@"select * FROM City", c.dbconn);
            da.Fill(ds);
            

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                a = new City(dr["Name"].ToString(), dr["Country"].ToString());
                a.Id = Convert.ToInt32(dr["IDCity"]); 
                list.Add(a);
                
            }


            return list;
        }

        
    }
}